<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <style>

      .light{
        background-color: white;
        color:black;

      }

      .dark{
        background-color: black;
        color: white;
      }

  </style>


  <!-- 夜间模式 -->
  <div class="light" style="height:500px" >这是一段话</div>
  <button>关灯</button>

  <script>
    let div = document.querySelector('div');
    let button = document.querySelector('button');
    button.onclick = function(){
      if(div.className == 'light'){
        div.className = 'dark';
        button.innerHTML = '开灯';
        
      }else if(div.className == 'dark'){
        div.className = 'light';
        button.innerHTML = '关灯';
      }
    }
  </script>
  
</body>
</html>